import { defineStore } from 'pinia'

export interface CrumbItem {
  name: string
  title: string
  path: string
}

export const useCrumbStore = defineStore('crumb', {
  // @ts-ignore
  persist: {
    enabled: true,
    strategies: [
      {
        storage: localStorage
      }
    ]
  },
  state: () => ({
    crumbList: [] as CrumbItem[]
  }),
  actions: {
    addCrumb(item: CrumbItem) {
      if(this.crumbList.some(crumb => crumb.name === item.name)) return
      if(item.name === 'Home') return
      this.crumbList.push(item)
    },
    delCrumb(index: number) {
      this.crumbList.splice(index, 1)
    },
    clearCrumb() {
      this.crumbList = []
    }
  }
})